package com.zlq.cn.util;

import java.text.DateFormat;
import java.text.SimpleDateFormat;
import java.time.LocalDateTime;
import java.util.Date;

public class DateUtils {
    private static final int MIN_HOUR = 0;
    private static final int MIN_MINUTE = 0;
    private static final int MIN_SECOND = 0;
    private static final int MAX_HOUR = 23;
    private static final int MAX_MINUTE = 59;
    private static final int MAX_SECOND = 59;

    public static LocalDateTime getDayMin(LocalDateTime localDateTime) {
        if (localDateTime == null) return null;
        return LocalDateTime.of(localDateTime.getYear(), localDateTime.getMonth(), localDateTime.getDayOfMonth(), MIN_HOUR, MIN_MINUTE, MIN_SECOND);
    }

    public static LocalDateTime getDayMax(LocalDateTime localDateTime) {
        if (localDateTime == null) return null;
        return LocalDateTime.of(localDateTime.getYear(), localDateTime.getMonth(), localDateTime.getDayOfMonth(), MAX_HOUR, MAX_MINUTE, MAX_SECOND);
    }

    public static String dateFormat(String reg, Date date) {
        DateFormat sdf = getDateFormat(reg);
        return sdf.format(date);
    }

    public static DateFormat getDateFormat(String reg) {
        return new SimpleDateFormat(reg);
    }
}
